home *** CD-ROM | disk | FTP | other *** search
- UNIT Font;
-
- {+----------------------------------------------------------------------------+
- | |
- | HodgePodge: An example Apple IIGS Desktop application |
- | |
- | Written in 65816 assembler and APW C by the Apple IIGS Tools Team |
- | Translated to TML Pascal by TML Systems, Inc. |
- | Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS" |
- | |
- | Copyright (c) 1986-87 by Apple Computer, Inc. |
- | Copyright (c) 1987 by TML Systems, Inc. |
- | |
- | -------------------------------- |
- | |
- | Pascal UNIT "FONT.PAS" : Font window drawing routines |
- | |
- +----------------------------------------------------------------------------+}
-
-
-
- INTERFACE
-
- USES
- HPIntfData, {HodgePodge Apple IIGS Toolbox Interface Units}
- HPIntfProc,
- HPIntfPdos,
-
- Globals; {HodgePodge Code Unit}
-
-
-
- procedure DispFontWindow; {Draw font window contents }
- function DoChooseFont: boolean; {Dialog for asking font size, etc.}
- procedure DoSetMono; {Sets flag and affects menu item }
- procedure ShowFont (theFontID: FontID; isMono: boolean); {Actually draw font}
-
-
-
-
-
- IMPLEMENTATION
-
-
-
- procedure DispFontWindow;
-
- {This is a Definition Procedure used to draw the contents of a Font
- window.}
-
- var tmpPort : GrafPortPtr;
- myDataHandle : WindDataH;
-
- begin {of DispFontWindow}
- tmpPort := GetPort;
- myDataHandle := WindDataH (GetWRefCon (tmpPort));
- with myDataHandle^^ do
- ShowFont (theFont,isMono);
- end; {of DispFontWindow}
-
-
-
- function DoChooseFont: boolean;
-
- {Display the Font Manager's dialog for the user to select a Font,
- font size, and font style.
-
- The function returns true if a font was chosen, else false if the Cancel
- button is pressed in the dialog. If a font is chosen, its FontID information
- is returned in the global variable DesiredFont. In addition, the
- global myReply.filename contains a string which is the font's file name.
-
- Because the call to ChooseFont actually changes the font of the current
- port, we must first save the current port and open a dummy one do that
- our current port is not affected.}
-
- var theFont : FontID;
- dummy : integer;
- tmpPort : GrafPortPtr;
- tmpPortRec : GrafPort;
- famName : Str255;
-
- begin {of DoChooseFont}
- tmpPort := GetPort;
- OpenPort (@tmpPortRec); {Save current port and open new one}
-
- theFont := ChooseFont (DesiredFont,0); {Do standard dialog box}
-
- if longint (theFont) = 0 then {Cancel was chosen}
- DoChooseFont := false
- else begin
- DesiredFont := theFont; {Update global DesiredFont}
- dummy := GetFamInfo (DesiredFont.famNum,famName);
- myReply.filename :=
- concat (famName,
- ' ',
- IntToString (DesiredFont.fontSize));
- DoChooseFont := true;
- end;
-
- ClosePort (@tmpPortRec);
- SetPort (tmpPort); {Restore current port}
-
- end; {of DoChooseFont}
-
-
-
- procedure DoSetMono;
-
- {This procedure flips the flag indicating whether we are currently
- displaying a font in mono-spacing or not, and updates the
- font menu item accordingly.}
-
- begin {of DoSetMono}
- if isMonoFont then
- SetMItem (MonoStr,MonoItem)
- else
- SetMItem (ProStr,MonoItem);
- isMonoFont := not isMonoFont;
- end; {of DoSetMono}
-
-
-
- procedure ShowFont (theFontID: FontID; isMono: boolean);
-
- var FontInfo : FontInfoRecord;
- CurrHeight : integer;
- i,j : integer;
- theCh : integer;
- currPt : Point;
- fontStr : Str255;
-
- begin {of ShowFont}
- InstallFont (theFontID,0);
- GetFontInfo (FontInfo);
- CurrHeight := FontInfo.ascent + FontInfo.descent + FontInfo.leading;
-
- i := GetFamInfo (theFontID.famNum,fontStr);
- fontStr := concat (fontStr,' ',IntToString (theFontID.fontSize));
-
- i := GetFontFlags;
- if isMono then
- i := BitOr (i,$0001) {Set bottom bit}
- else
- i := BitAnd (i,$0000); {Clear bottom bit}
- SetFontFlags(i);
-
- MoveTo (5,CurrHeight);
- DrawString (fontStr);
-
- MoveTo (5,CurrHeight * 3);
- DrawString ('The quick brown fox jumps over the lazy dog.');
- MoveTo (5,CurrHeight * 4);
- DrawString ('She sells sea shells down by the sea shore.');
-
- MoveTo (5,CurrHeight * 5);
-
- for i := 0 to 7 do begin
- GetPen (currPt);
- MoveTo (5,currPt.v + CurrHeight);
- theCh := i * 32;
- for j := 1 to 32 do begin
- fontStr [j] := chr (theCh);
- inc (theCh);
- end;
- fontStr [0] := chr (32);
- DrawString (fontStr);
- end;
- end; {of ShowFont}
-
-
-
- END.
-